﻿using System;
using System.Globalization;
using System.Web;
using System.Web.Helpers;
using System.Web.Mvc;
using Adf.Core.Db;
using Adf.Core.Entity;
using Adf.Core.Util;
using Adf.FrameWork.Service;
using CYQ.Data.Table;
using CYQ.Data.Tool;
using Test.Interface;

namespace Test.Implement
{
    public class LoginImpl : ILogin
    {



        private const String CurrentTableName = "adf_user";
        private const String VCurrentTableName = "adf_user";






        /// <summary>
        /// 初始化值
        /// 袁赛
        /// 2020-5-22
        /// </summary>
        /// <returns></returns>
        public MDataRow InitDataRow()
        {
            MDataRow mDataRow = new MDataRow(DBTool.GetColumns(CurrentTableName));
            return mDataRow;
        }

        /// <summary>
        /// 获得实体
        /// 袁赛
        /// </summary>
        /// <param name="sUserCode">通知编号</param>
        /// <param name="bCache">是否启用缓存</param>
        /// <returns></returns>
        public MDataRow GetEntityWithUserCode(string sUserCode, bool bCache = false)
        {
            String sWhere = "UserCode=" + DbService.SetQuotesValue(sUserCode);
            String cacheKey = "test-" + sUserCode;
            return DbService.GetOne(VCurrentTableName, sWhere, cacheKey, bCache);
        }



        /// <summary>
        /// 增加数据
        /// 袁赛
        /// </summary>
        /// <param name="dataRow"></param>
        /// 
        /// <returns></returns>
        public ExeMsgInfo Add(MDataRow dataRow)
        {
            throw new System.NotImplementedException();
        }

        /// <summary>
        /// 更新数据
        /// 袁赛
        /// </summary>
        /// <param name="dataRow"></param>
        /// <returns></returns>
        public ExeMsgInfo Update(MDataRow dataRow)
        {
            throw new System.NotImplementedException();
        }





        /// <summary>
        /// 删除数据
        /// 袁赛
        /// </summary>
        /// <param name="sUserCode">通知编号</param>
        /// <returns></returns>
        public ExeMsgInfo DeleteByUserCode(string sUserCode)
        {
            throw new System.NotImplementedException();
        }

        /// <summary>
        ///获得列表
        /// 袁赛
        /// </summary>
        /// <param name="pageIndex">页码</param>
        /// <param name="pageSize">页大小</param>
        /// <param name="orderBy">排序</param>
        /// <param name="recordCount">总数</param>
        /// <param name="pageCount">总页数</param>
        /// <returns></returns>
        public MDataTable GetList(int pageIndex, int pageSize, string orderBy, ref int recordCount, ref int pageCount)
        {
            throw new System.NotImplementedException();
        }








        /// <summary>
        /// 获得用户输入密码，账号验证是否正确
        /// </summary>
        /// <param name="sUserCode"></param>
        /// <param name="sPassWord"></param>
        /// <returns></returns>
        public ExeMsgInfo CheckUserLogin(string sUserCode, string sPassWord)
        {
            ExeMsgInfo exeMsgInfo = new ExeMsgInfo();
            UserImpl user = new UserImpl();
            MDataRow userRow = user.GetEntityWithUserCode(sUserCode,false);
            //获得数据库中对应的密码
      
            String sTableUserPassWord = userRow.Get("userpassword", "");
            //获得页面用户输入的密码
            String sGetPassWord = Md5Helper.ToMd5(sPassWord);
            if (sGetPassWord == sTableUserPassWord)
            {
                exeMsgInfo.RetStatus = 100;
                exeMsgInfo.RetValue = "登录成功！";
                return (exeMsgInfo);


            }
            else
            {
                exeMsgInfo.RetStatus = 400;
                exeMsgInfo.RetValue = "用户名或密码错误！";
                return (exeMsgInfo);
            }

         
        }




    }
}